#include <stdio.h>

int main()
{
	int n = 0;
	int n2 = 0;
	scanf("%d", &n);
	do {
		n2 = 0;
		while ( n != 0 ) {
			n2 += n % 10;
			n = n / 10;
		}
		n = n2;
	}while ( n2 > 10 );
	printf("%d", n2);
	return 0;
}
